Code
import ibis
import pandas as pd
from ibis import _
ibis.options.interactive = True
pd.options.display.max_rows=1000import ibis
import pandas as pd
from ibis import _
ibis.options.interactive = True
pd.options.display.max_rows=1000con = ibis.postgres.connect(
host='localhost',
user='postgres',
password='your_password',
port=5432,
database='analysis',
)con.list_tables()['us_counties_pop_est_2010_2020_raw',
'regions',
'divisions',
'us_states',
'npopchg_by_county_2010_2020',
'npopchg_by_state_2010_2020']
The raw or original data we want is saved as a Postgres table called us_counties_pop_est_2010_2020_raw:
us_counties_pop = con.table('us_counties_pop_est_2010_2020_raw')us_counties_pop┏━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┓ ┃ sumlev ┃ region ┃ division ┃ state ┃ county ┃ stname ┃ ctyname ┃ census2010pop ┃ estimatesbase2010 ┃ popestimate2010 ┃ popestimate2011 ┃ popestimate2012 ┃ popestimate2013 ┃ popestimate2014 ┃ popestimate2015 ┃ popestimate2016 ┃ popestimate2017 ┃ popestimate2018 ┃ popestimate2019 ┃ popestimate2020 ┃ npopchg_2010 ┃ npopchg_2011 ┃ npopchg_2012 ┃ npopchg_2013 ┃ npopchg_2014 ┃ npopchg_2015 ┃ npopchg_2016 ┃ npopchg_2017 ┃ npopchg_2018 ┃ npopchg_2019 ┃ npopchg_2020 ┃ births2010 ┃ births2011 ┃ births2012 ┃ births2013 ┃ births2014 ┃ births2015 ┃ births2016 ┃ births2017 ┃ births2018 ┃ births2019 ┃ births2020 ┃ deaths2010 ┃ deaths2011 ┃ deaths2012 ┃ deaths2013 ┃ deaths2014 ┃ deaths2015 ┃ deaths2016 ┃ deaths2017 ┃ deaths2018 ┃ deaths2019 ┃ deaths2020 ┃ naturalinc2010 ┃ naturalinc2011 ┃ naturalinc2012 ┃ naturalinc2013 ┃ naturalinc2014 ┃ naturalinc2015 ┃ naturalinc2016 ┃ naturalinc2017 ┃ naturalinc2018 ┃ naturalinc2019 ┃ naturalinc2020 ┃ internationalmig2010 ┃ internationalmig2011 ┃ internationalmig2012 ┃ internationalmig2013 ┃ internationalmig2014 ┃ internationalmig2015 ┃ internationalmig2016 ┃ internationalmig2017 ┃ internationalmig2018 ┃ internationalmig2019 ┃ internationalmig2020 ┃ domesticmig2010 ┃ domesticmig2011 ┃ domesticmig2012 ┃ domesticmig2013 ┃ domesticmig2014 ┃ domesticmig2015 ┃ domesticmig2016 ┃ domesticmig2017 ┃ domesticmig2018 ┃ domesticmig2019 ┃ domesticmig2020 ┃ netmig2010 ┃ netmig2011 ┃ netmig2012 ┃ netmig2013 ┃ netmig2014 ┃ netmig2015 ┃ netmig2016 ┃ netmig2017 ┃ netmig2018 ┃ netmig2019 ┃ netmig2020 ┃ residual2010 ┃ residual2011 ┃ residual2012 ┃ residual2013 ┃ residual2014 ┃ residual2015 ┃ residual2016 ┃ residual2017 ┃ residual2018 ┃ residual2019 ┃ residual2020 ┃ gqestimatesbase2010 ┃ gqestimates2010 ┃ gqestimates2011 ┃ gqestimates2012 ┃ gqestimates2013 ┃ gqestimates2014 ┃ gqestimates2015 ┃ gqestimates2016 ┃ gqestimates2017 ┃ gqestimates2018 ┃ gqestimates2019 ┃ gqestimates2020 ┃ rbirth2011 ┃ rbirth2012 ┃ rbirth2013 ┃ rbirth2014 ┃ rbirth2015 ┃ rbirth2016 ┃ rbirth2017 ┃ rbirth2018 ┃ rbirth2019 ┃ rbirth2020 ┃ rdeath2011 ┃ rdeath2012 ┃ rdeath2013 ┃ rdeath2014 ┃ rdeath2015 ┃ rdeath2016 ┃ rdeath2017 ┃ rdeath2018 ┃ rdeath2019 ┃ rdeath2020 ┃ rnaturalinc2011 ┃ rnaturalinc2012 ┃ rnaturalinc2013 ┃ rnaturalinc2014 ┃ rnaturalinc2015 ┃ rnaturalinc2016 ┃ rnaturalinc2017 ┃ rnaturalinc2018 ┃ rnaturalinc2019 ┃ rnaturalinc2020 ┃ rinternationalmig2011 ┃ rinternationalmig2012 ┃ rinternationalmig2013 ┃ rinternationalmig2014 ┃ rinternationalmig2015 ┃ rinternationalmig2016 ┃ rinternationalmig2017 ┃ rinternationalmig2018 ┃ rinternationalmig2019 ┃ rinternationalmig2020 ┃ rdomesticmig2011 ┃ rdomesticmig2012 ┃ rdomesticmig2013 ┃ rdomesticmig2014 ┃ rdomesticmig2015 ┃ rdomesticmig2016 ┃ rdomesticmig2017 ┃ rdomesticmig2018 ┃ rdomesticmig2019 ┃ rdomesticmig2020 ┃ rnetmig2011 ┃ rnetmig2012 ┃ rnetmig2013 ┃ rnetmig2014 ┃ rnetmig2015 ┃ rnetmig2016 ┃ rnetmig2017 ┃ rnetmig2018 ┃ rnetmig2019 ┃ rnetmig2020 ┃ ┡━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━┩ │ string │ int16 │ int16 │ string │ string │ string │ string │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ int32 │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ decimal(15, 10) │ ├────────┼────────┼──────────┼────────┼────────┼─────────┼─────────────────┼───────────────┼───────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼──────────────┼──────────────┼──────────────┼──────────────┼──────────────┼──────────────┼──────────────┼──────────────┼──────────────┼──────────────┼──────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────────┼────────────────┼────────────────┼────────────────┼────────────────┼────────────────┼────────────────┼────────────────┼────────────────┼────────────────┼────────────────┼──────────────────────┼──────────────────────┼──────────────────────┼──────────────────────┼──────────────────────┼──────────────────────┼──────────────────────┼──────────────────────┼──────────────────────┼──────────────────────┼──────────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼──────────────┼──────────────┼──────────────┼──────────────┼──────────────┼──────────────┼──────────────┼──────────────┼──────────────┼──────────────┼──────────────┼─────────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼───────────────────────┼───────────────────────┼───────────────────────┼───────────────────────┼───────────────────────┼───────────────────────┼───────────────────────┼───────────────────────┼───────────────────────┼───────────────────────┼──────────────────┼──────────────────┼──────────────────┼──────────────────┼──────────────────┼──────────────────┼──────────────────┼──────────────────┼──────────────────┼──────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┼─────────────────┤ │ 40 │ 3 │ 6 │ 1 │ 0 │ Alabama │ Alabama │ 4779736 │ 4780118 │ 4785514 │ 4799642 │ 4816632 │ 4831586 │ 4843737 │ 4854803 │ 4866824 │ 4877989 │ 4891628 │ 4907965 │ 4921532 │ 5396 │ 14128 │ 16990 │ 14954 │ 12151 │ 11066 │ 12021 │ 11165 │ 13639 │ 16337 │ 13567 │ 14202 │ 59699 │ 59074 │ 57943 │ 58914 │ 59653 │ 59695 │ 58644 │ 58665 │ 57251 │ 56739 │ 11077 │ 48837 │ 48363 │ 50853 │ 49720 │ 51878 │ 51711 │ 53196 │ 54560 │ 54038 │ 58354 │ 3125 │ 10862 │ 10711 │ 7090 │ 9194 │ 7775 │ 7984 │ 5448 │ 4105 │ 3213 │ -1615 │ 1053 │ 5162 │ 6282 │ 5494 │ 4159 │ 5095 │ 6301 │ 3546 │ 3940 │ 2293 │ 2078 │ 1225 │ -1903 │ -114 │ 2294 │ -996 │ -1553 │ -2148 │ 2287 │ 5664 │ 10828 │ 13115 │ 2278 │ 3259 │ 6168 │ 7788 │ 3163 │ 3542 │ 4153 │ 5833 │ 9604 │ 13121 │ 15193 │ -7 │ 7 │ 111 │ 76 │ -206 │ -251 │ -116 │ -116 │ -70 │ 3 │ -11 │ 116185 │ 116242 │ 115184 │ 115810 │ 116946 │ 119052 │ 119980 │ 118641 │ 117111 │ 116600 │ 116778 │ 116767 │ 12.4565526110 │ 12.2862555710 │ 12.0111299310 │ 12.1781980820 │ 12.3014391860 │ 12.2808661550 │ 12.0359415820 │ 12.0096826720 │ 11.6843628100 │ 11.5446395680 │ 10.1901314910 │ 10.0585736220 │ 10.5414284790 │ 10.2776930550 │ 10.6981050760 │ 10.6383427380 │ 10.9178082740 │ 11.1693221960 │ 11.0286212910 │ 11.8732423440 │ 2.2664211203 │ 2.2276819483 │ 1.4697014516 │ 1.9005050271 │ 1.6033341101 │ 1.6425234171 │ 1.1181333085 │ 0.8403604768 │ 0.6557415191 │ -0.3286027760 │ 1.0770821049 │ 1.3065351507 │ 1.1388631559 │ 0.8597129005 │ 1.0506736065 │ 1.2962850766 │ 0.7277717900 │ 0.8065822846 │ 0.4679786191 │ 0.4228090206 │ -0.3970723060 │ -0.0237098070 │ 0.4755282271 │ -0.2058845990 │ -0.3202543890 │ -0.4419013400 │ 0.4693779142 │ 1.1595132133 │ 2.2098876964 │ 2.6684987034 │ 0.6800097985 │ 1.2828253438 │ 1.6143913829 │ 0.6538283011 │ 0.7304192177 │ 0.8543837364 │ 1.1971497042 │ 1.9660954979 │ 2.6778663155 │ 3.0913077241 │ │ 50 │ 3 │ 6 │ 1 │ 1 │ Alabama │ Autauga County │ 54571 │ 54582 │ 54761 │ 55229 │ 54970 │ 54747 │ 54922 │ 54903 │ 55302 │ 55448 │ 55533 │ 55769 │ 56145 │ 179 │ 468 │ -259 │ -223 │ 175 │ -19 │ 399 │ 146 │ 85 │ 236 │ 376 │ 151 │ 639 │ 615 │ 570 │ 637 │ 652 │ 675 │ 667 │ 651 │ 592 │ 606 │ 157 │ 514 │ 560 │ 584 │ 572 │ 585 │ 547 │ 574 │ 563 │ 552 │ 582 │ -6 │ 125 │ 55 │ -14 │ 65 │ 67 │ 128 │ 93 │ 88 │ 40 │ 24 │ 28 │ 16 │ 0 │ 19 │ 19 │ 23 │ 7 │ -3 │ 2 │ -14 │ -8 │ 147 │ 327 │ -329 │ -226 │ 102 │ -107 │ 266 │ 58 │ -3 │ 208 │ 360 │ 175 │ 343 │ -329 │ -207 │ 121 │ -84 │ 273 │ 55 │ -1 │ 194 │ 352 │ 10 │ 0 │ 15 │ -2 │ -11 │ -2 │ -2 │ -2 │ -2 │ 2 │ 0 │ 455 │ 455 │ 455 │ 455 │ 455 │ 455 │ 455 │ 455 │ 455 │ 455 │ 455 │ 455 │ 11.6192381130 │ 11.1616257860 │ 10.3903679470 │ 11.6167741110 │ 11.8734350100 │ 12.2498979180 │ 12.0451467270 │ 11.7317378650 │ 10.6377243890 │ 10.8297442680 │ 9.3463042095 │ 10.1634316100 │ 10.6455699660 │ 10.4313889980 │ 10.6533120870 │ 9.9269543124 │ 10.3656884880 │ 10.1458808260 │ 9.9189592280 │ 10.4008435050 │ 2.2729339031 │ 0.9981941760 │ -0.2552020200 │ 1.1853851134 │ 1.2201229228 │ 2.3229436051 │ 1.6794582393 │ 1.5858570386 │ 0.7187651615 │ 0.4289007631 │ 0.2909355396 │ 0.0000000000 │ 0.3463455982 │ 0.3464971870 │ 0.4188481675 │ 0.1270359784 │ -0.0541760720 │ 0.0360422054 │ -0.2515678070 │ -0.1429669210 │ 5.9459950905 │ -5.9710160710 │ -4.1196897470 │ 1.8601427933 │ -1.9485545190 │ 4.8273671793 │ 1.0474040632 │ -0.0540633080 │ 3.7375788396 │ 6.4335114463 │ 6.2369306301 │ -5.9710160710 │ -3.7733441490 │ 2.2066399803 │ -1.5297063510 │ 4.9544031578 │ 0.9932279910 │ -0.0180211030 │ 3.4860110330 │ 6.2905445253 │ │ 50 │ 3 │ 6 │ 1 │ 3 │ Alabama │ Baldwin County │ 182265 │ 182263 │ 183121 │ 186579 │ 190203 │ 194978 │ 199306 │ 203101 │ 207787 │ 212737 │ 218071 │ 223565 │ 229287 │ 858 │ 3458 │ 3624 │ 4775 │ 4328 │ 3795 │ 4686 │ 4950 │ 5334 │ 5494 │ 5722 │ 514 │ 2186 │ 2092 │ 2162 │ 2215 │ 2261 │ 2286 │ 2313 │ 2297 │ 2322 │ 2317 │ 534 │ 1829 │ 1883 │ 1902 │ 1988 │ 2099 │ 2021 │ 2103 │ 2325 │ 2386 │ 2543 │ -20 │ 357 │ 209 │ 260 │ 227 │ 162 │ 265 │ 210 │ -28 │ -64 │ -226 │ 51 │ 192 │ 273 │ 240 │ 141 │ 165 │ 211 │ 104 │ 118 │ 63 │ 60 │ 780 │ 2896 │ 3056 │ 4175 │ 3861 │ 3437 │ 4193 │ 4622 │ 5234 │ 5511 │ 5918 │ 831 │ 3088 │ 3329 │ 4415 │ 4002 │ 3602 │ 4404 │ 4726 │ 5352 │ 5574 │ 5978 │ 47 │ 13 │ 86 │ 100 │ 99 │ 31 │ 17 │ 14 │ 10 │ -16 │ -30 │ 2307 │ 2307 │ 2263 │ 2242 │ 2296 │ 2331 │ 2337 │ 2276 │ 2192 │ 2171 │ 2268 │ 2268 │ 11.8258047070 │ 11.1045644430 │ 11.2258912040 │ 11.2355560970 │ 11.2373790710 │ 11.1271197990 │ 11.0005612050 │ 10.6636831260 │ 10.5154471100 │ 10.2329237810 │ 9.8945090614 │ 9.9951696206 │ 9.8758765360 │ 10.0841018150 │ 10.4322240920 │ 9.8372305835 │ 10.0018072690 │ 10.7936714270 │ 10.8052785550 │ 11.2310423710 │ 1.9312956451 │ 1.1093948225 │ 1.3500146684 │ 1.1514542817 │ 0.8051549799 │ 1.2898892156 │ 0.9987539356 │ -0.1299883010 │ -0.2898314450 │ -0.9981185910 │ 1.0386800108 │ 1.4491138112 │ 1.2461673862 │ 0.7152205010 │ 0.8200652573 │ 1.0270438660 │ 0.4946209967 │ 0.5478078402 │ 0.2853028286 │ 0.2649872364 │ 15.6667568300 │ 16.2215817100 │ 21.6781201560 │ 19.5848677600 │ 17.0822078140 │ 20.4094546450 │ 21.9820985250 │ 24.2985274180 │ 24.9572045760 │ 26.1365744220 │ 16.7054368410 │ 17.6706955220 │ 22.9242875430 │ 20.3000882610 │ 17.9022730720 │ 21.4364985110 │ 22.4767195210 │ 24.8463352580 │ 25.2425074040 │ 26.4015616580 │ │ 50 │ 3 │ 6 │ 1 │ 5 │ Alabama │ Barbour County │ 27457 │ 27454 │ 27325 │ 27344 │ 27172 │ 26946 │ 26768 │ 26300 │ 25828 │ 25169 │ 24887 │ 24657 │ 24589 │ -129 │ 19 │ -172 │ -226 │ -178 │ -468 │ -472 │ -659 │ -282 │ -230 │ -68 │ 70 │ 335 │ 301 │ 284 │ 265 │ 274 │ 284 │ 276 │ 273 │ 248 │ 250 │ 131 │ 324 │ 286 │ 293 │ 308 │ 332 │ 279 │ 297 │ 335 │ 322 │ 334 │ -61 │ 11 │ 15 │ -9 │ -43 │ -58 │ 5 │ -21 │ -62 │ -74 │ -84 │ 0 │ -5 │ -11 │ -8 │ 5 │ 13 │ 13 │ 9 │ 8 │ 6 │ 6 │ -69 │ 14 │ -176 │ -211 │ -141 │ -429 │ -492 │ -650 │ -228 │ -161 │ 10 │ -69 │ 9 │ -187 │ -219 │ -136 │ -416 │ -479 │ -641 │ -220 │ -155 │ 16 │ 1 │ -1 │ 0 │ 2 │ 1 │ 6 │ 2 │ 3 │ 0 │ -1 │ 0 │ 3193 │ 3193 │ 3381 │ 3391 │ 3388 │ 3353 │ 3195 │ 2977 │ 2819 │ 2813 │ 2778 │ 2777 │ 12.2555744570 │ 11.0426296870 │ 10.4955837240 │ 9.8670737610 │ 10.3263737090 │ 10.8962553710 │ 10.8241661270 │ 10.9077832830 │ 10.0113030840 │ 10.1531088820 │ 11.8531526090 │ 10.4923325260 │ 10.8281902510 │ 11.4681461070 │ 12.5122484360 │ 10.7044198900 │ 11.6477439850 │ 13.3850087900 │ 12.9985467460 │ 13.5645534660 │ 0.4024218478 │ 0.5502971605 │ -0.3326065260 │ -1.6010723460 │ -2.1858747270 │ 0.1918354819 │ -0.8235778580 │ -2.4772255070 │ -2.9872436620 │ -3.4114445840 │ -0.1829190220 │ -0.4035512510 │ -0.2956502460 │ 0.1861712030 │ 0.4899374388 │ 0.4987722529 │ 0.3529619389 │ 0.3196420010 │ 0.2422089456 │ 0.2436746132 │ 0.5121732609 │ -6.4568200160 │ -7.7977752320 │ -5.2500279260 │ -16.1679354800 │ -18.8766114200 │ -25.4916955900 │ -9.1097970270 │ -6.4992733730 │ 0.4061243553 │ 0.3292542391 │ -6.8603712670 │ -8.0934254780 │ -5.0638567230 │ -15.6779980400 │ -18.3778391700 │ -25.1387336500 │ -8.7901550260 │ -6.2570644280 │ 0.6497989684 │ │ 50 │ 3 │ 6 │ 1 │ 7 │ Alabama │ Bibb County │ 22915 │ 22904 │ 22858 │ 22736 │ 22657 │ 22510 │ 22541 │ 22553 │ 22590 │ 22532 │ 22300 │ 22313 │ 22136 │ -46 │ -122 │ -79 │ -147 │ 31 │ 12 │ 37 │ -58 │ -232 │ 13 │ -177 │ 44 │ 265 │ 245 │ 258 │ 253 │ 252 │ 299 │ 267 │ 243 │ 238 │ 249 │ 32 │ 277 │ 236 │ 276 │ 250 │ 266 │ 243 │ 251 │ 314 │ 232 │ 266 │ 12 │ -12 │ 9 │ -18 │ 3 │ -14 │ 56 │ 16 │ -71 │ 6 │ -17 │ 0 │ 12 │ 19 │ 20 │ 14 │ 14 │ 11 │ 7 │ 8 │ 7 │ 6 │ -59 │ -124 │ -105 │ -151 │ 18 │ 15 │ -30 │ -80 │ -171 │ -1 │ -166 │ -59 │ -112 │ -86 │ -131 │ 32 │ 29 │ -19 │ -73 │ -163 │ 6 │ -160 │ 1 │ 2 │ -2 │ 2 │ -4 │ -3 │ 0 │ -1 │ 2 │ 1 │ 0 │ 2224 │ 2224 │ 2224 │ 2228 │ 2224 │ 2247 │ 2255 │ 2204 │ 2153 │ 2147 │ 2122 │ 2121 │ 11.6243365360 │ 10.7946159100 │ 11.4242699320 │ 11.2317151670 │ 11.1766532130 │ 13.2467935230 │ 11.8345818000 │ 10.8404710920 │ 10.6695357860 │ 11.2038516050 │ 12.1507215860 │ 10.3980789990 │ 12.2213120200 │ 11.0985327740 │ 11.7975783920 │ 10.7657887160 │ 11.1253933780 │ 14.0078515350 │ 10.4005558920 │ 11.9687732010 │ -0.5263850510 │ 0.3965369110 │ -0.7970420880 │ 0.1331823933 │ -0.6209251790 │ 2.4810048069 │ 0.7091884225 │ -3.1673804430 │ 0.2689798938 │ -0.7649215960 │ 0.5263850507 │ 0.8371334787 │ 0.8856023203 │ 0.6215178353 │ 0.6209251785 │ 0.4873402299 │ 0.3102699348 │ 0.3568879372 │ 0.3138098760 │ 0.2699723278 │ -5.4393121900 │ -4.6262639610 │ -6.6862975180 │ 0.7990943597 │ 0.6652769770 │ -1.3291097180 │ -3.5459421120 │ -7.6284796570 │ -0.0448299820 │ -7.4692344030 │ -4.9129271400 │ -3.7891304830 │ -5.8006951980 │ 1.4206121951 │ 1.2862021555 │ -0.8417694880 │ -3.2356721780 │ -7.2715917200 │ 0.2689798938 │ -7.1992620760 │ │ 50 │ 3 │ 6 │ 1 │ 9 │ Alabama │ Blount County │ 57322 │ 57322 │ 57372 │ 57561 │ 57585 │ 57630 │ 57536 │ 57535 │ 57487 │ 57801 │ 57770 │ 57840 │ 57879 │ 50 │ 189 │ 24 │ 45 │ -94 │ -1 │ -48 │ 314 │ -31 │ 70 │ 39 │ 181 │ 741 │ 714 │ 647 │ 620 │ 715 │ 675 │ 681 │ 675 │ 673 │ 665 │ 132 │ 569 │ 587 │ 582 │ 591 │ 634 │ 651 │ 721 │ 718 │ 658 │ 697 │ 49 │ 172 │ 127 │ 65 │ 29 │ 81 │ 24 │ -40 │ -43 │ 15 │ -32 │ -2 │ -8 │ 8 │ 49 │ 43 │ 15 │ 32 │ 0 │ 4 │ -4 │ 1 │ 9 │ 28 │ -100 │ -65 │ -158 │ -90 │ -102 │ 357 │ 10 │ 58 │ 68 │ 7 │ 20 │ -92 │ -16 │ -115 │ -75 │ -70 │ 357 │ 14 │ 54 │ 69 │ -6 │ -3 │ -11 │ -4 │ -8 │ -7 │ -2 │ -3 │ -2 │ 1 │ 2 │ 489 │ 489 │ 489 │ 489 │ 489 │ 489 │ 489 │ 489 │ 489 │ 489 │ 489 │ 489 │ 12.8944689510 │ 12.4016466050 │ 11.2311764960 │ 10.7670666690 │ 12.4271102190 │ 11.7368851180 │ 11.8138921660 │ 11.6811310800 │ 11.6425914710 │ 11.4933589130 │ 9.9014208278 │ 10.1957514810 │ 10.1028511910 │ 10.2634458090 │ 11.0192837470 │ 11.3195736470 │ 12.5078065370 │ 12.4252623930 │ 11.3830983480 │ 12.0464228000 │ 2.9930481237 │ 2.2058951245 │ 1.1283253049 │ 0.5036208603 │ 1.4078264724 │ 0.4173114708 │ -0.6939143710 │ -0.7441313130 │ 0.2594931234 │ -0.5530638880 │ -0.1392115410 │ 0.1389540236 │ 0.8505836914 │ 0.7467481722 │ 0.2607086060 │ 0.5564152945 │ 0.0000000000 │ 0.0692215175 │ -0.0691981660 │ 0.0172832465 │ 0.4872403922 │ -1.7369252950 │ -1.1283253050 │ -2.7438653770 │ -1.5642516360 │ -1.7735737510 │ 6.1931857609 │ 0.1730537938 │ 1.0033734106 │ 1.1752607610 │ 0.3480288516 │ -1.5979712710 │ -0.2777416140 │ -1.9971172050 │ -1.3035430300 │ -1.2171584570 │ 6.1931857609 │ 0.2422753113 │ 0.9341752444 │ 1.1925440075 │ │ 50 │ 3 │ 6 │ 1 │ 11 │ Alabama │ Bullock County │ 10914 │ 10913 │ 10876 │ 10680 │ 10610 │ 10557 │ 10668 │ 10404 │ 10397 │ 10181 │ 10165 │ 10144 │ 9976 │ -37 │ -196 │ -70 │ -53 │ 111 │ -264 │ -7 │ -216 │ -16 │ -21 │ -168 │ 37 │ 172 │ 121 │ 131 │ 123 │ 124 │ 147 │ 129 │ 112 │ 110 │ 114 │ 53 │ 133 │ 117 │ 119 │ 116 │ 133 │ 131 │ 143 │ 120 │ 95 │ 116 │ -16 │ 39 │ 4 │ 12 │ 7 │ -9 │ 16 │ -14 │ -8 │ 15 │ -2 │ 1 │ 19 │ 8 │ 18 │ 6 │ 1 │ 8 │ 10 │ 14 │ 1 │ 5 │ -24 │ -255 │ -81 │ -83 │ 94 │ -260 │ -31 │ -213 │ -23 │ -37 │ -170 │ -23 │ -236 │ -73 │ -65 │ 100 │ -259 │ -23 │ -203 │ -9 │ -36 │ -165 │ 2 │ 1 │ -1 │ 0 │ 4 │ 4 │ 0 │ 1 │ 1 │ 0 │ -1 │ 1690 │ 1690 │ 1690 │ 1779 │ 1719 │ 1757 │ 1661 │ 1729 │ 1662 │ 1663 │ 1705 │ 1704 │ 15.9584338470 │ 11.3668388910 │ 12.3777578310 │ 11.5901060070 │ 11.7691723610 │ 14.1339358680 │ 12.5376615800 │ 11.0095350440 │ 10.8326357770 │ 11.3320079520 │ 12.3399517540 │ 10.9910756220 │ 11.2439174190 │ 10.9305064780 │ 12.6233864840 │ 12.5955482910 │ 13.8983380310 │ 11.7959304040 │ 9.3554581713 │ 11.5308151090 │ 3.6184820932 │ 0.3757632691 │ 1.1338404120 │ 0.6595995289 │ -0.8542141230 │ 1.5383875775 │ -1.3606764510 │ -0.7863953600 │ 1.4771776060 │ -0.1988071570 │ 1.7628502505 │ 0.7515265383 │ 1.7007606179 │ 0.5653710247 │ 0.0949126803 │ 0.7691937888 │ 0.9719117504 │ 1.3761918805 │ 0.0984785071 │ 0.4970178926 │ -23.6593059900 │ -7.6092062000 │ -7.8423961830 │ 8.8574793875 │ -24.6772968900 │ -2.9806259310 │ -20.7017202800 │ -2.2608866610 │ -3.6437047610 │ -16.8986083500 │ -21.8964557400 │ -6.8576796620 │ -6.1416355650 │ 9.4228504122 │ -24.5823842100 │ -2.2114321430 │ -19.7298085300 │ -0.8846947800 │ -3.5452262540 │ -16.4015904600 │ │ 50 │ 3 │ 6 │ 1 │ 13 │ Alabama │ Butler County │ 20947 │ 20940 │ 20933 │ 20867 │ 20672 │ 20359 │ 20332 │ 20168 │ 20040 │ 19911 │ 19675 │ 19501 │ 19504 │ -7 │ -66 │ -195 │ -313 │ -27 │ -164 │ -128 │ -129 │ -236 │ -174 │ 3 │ 66 │ 273 │ 242 │ 240 │ 252 │ 238 │ 236 │ 239 │ 220 │ 205 │ 200 │ 66 │ 264 │ 274 │ 262 │ 287 │ 276 │ 253 │ 269 │ 272 │ 272 │ 266 │ 0 │ 9 │ -32 │ -22 │ -35 │ -38 │ -17 │ -30 │ -52 │ -67 │ -66 │ 0 │ 2 │ 6 │ 8 │ 22 │ 28 │ 44 │ 23 │ 21 │ 19 │ 16 │ -4 │ -77 │ -170 │ -304 │ -11 │ -153 │ -154 │ -121 │ -205 │ -124 │ 52 │ -4 │ -75 │ -164 │ -296 │ 11 │ -125 │ -110 │ -98 │ -184 │ -105 │ 68 │ -3 │ 0 │ 1 │ 5 │ -3 │ -1 │ -1 │ -1 │ 0 │ -2 │ 1 │ 333 │ 333 │ 333 │ 333 │ 333 │ 333 │ 333 │ 333 │ 333 │ 333 │ 333 │ 333 │ 13.0622009570 │ 11.6517008110 │ 11.6984718870 │ 12.3860313090 │ 11.7530864200 │ 11.7389574210 │ 11.9646567040 │ 11.1150406710 │ 10.4655911780 │ 10.2550955010 │ 12.6315789470 │ 13.1924215800 │ 12.7708318100 │ 14.1063134350 │ 13.6296296300 │ 12.5845602870 │ 13.4664964580 │ 13.7422321020 │ 13.8860526850 │ 13.6392770160 │ 0.4306220096 │ -1.5407207680 │ -1.0723599230 │ -1.7202821260 │ -1.8765432100 │ -0.8456028650 │ -1.5018397540 │ -2.6271914310 │ -3.4204615070 │ -3.3841815150 │ 0.0956937799 │ 0.2888851441 │ 0.3899490629 │ 1.0813201937 │ 1.3827160494 │ 2.1886191803 │ 1.1514104778 │ 1.0609811550 │ 0.9699816214 │ 0.8204076400 │ -3.6842105260 │ -8.1850790820 │ -14.8180643900 │ -0.5406600970 │ -7.5555555560 │ -7.6601671310 │ -6.0574203400 │ -10.3571969900 │ -6.3304063710 │ 2.6663248301 │ -3.5885167460 │ -7.8961939380 │ -14.4281153300 │ 0.5406600968 │ -6.1728395060 │ -5.4715479510 │ -4.9060098620 │ -9.2962158340 │ -5.3604247500 │ 3.4867324702 │ │ 50 │ 3 │ 6 │ 1 │ 15 │ Alabama │ Calhoun County │ 118572 │ 118533 │ 118420 │ 117767 │ 117227 │ 116528 │ 115991 │ 115550 │ 115036 │ 114746 │ 114298 │ 114070 │ 113469 │ -113 │ -653 │ -540 │ -699 │ -537 │ -441 │ -514 │ -290 │ -448 │ -228 │ -601 │ 316 │ 1384 │ 1356 │ 1307 │ 1316 │ 1386 │ 1365 │ 1338 │ 1287 │ 1271 │ 1230 │ 311 │ 1325 │ 1359 │ 1411 │ 1395 │ 1455 │ 1475 │ 1393 │ 1645 │ 1486 │ 1553 │ 5 │ 59 │ -3 │ -104 │ -79 │ -69 │ -110 │ -55 │ -358 │ -215 │ -323 │ 3 │ 39 │ 81 │ 68 │ 84 │ 77 │ 98 │ 31 │ 50 │ -1 │ 10 │ -113 │ -752 │ -607 │ -660 │ -533 │ -441 │ -500 │ -260 │ -136 │ -15 │ -289 │ -110 │ -713 │ -526 │ -592 │ -449 │ -364 │ -402 │ -229 │ -86 │ -16 │ -279 │ -8 │ 1 │ -11 │ -3 │ -9 │ -8 │ -2 │ -6 │ -4 │ 3 │ 1 │ 2933 │ 2933 │ 2882 │ 2958 │ 2813 │ 2799 │ 2774 │ 2762 │ 2743 │ 2830 │ 3286 │ 3285 │ 11.7195273240 │ 11.5407201890 │ 11.1826484990 │ 11.3195050730 │ 11.9719617690 │ 11.8394004840 │ 11.6458208210 │ 11.2380154030 │ 11.1311567290 │ 10.8113334420 │ 11.2199231960 │ 11.5662527550 │ 12.0724690380 │ 11.9990194350 │ 12.5679685240 │ 12.7934913650 │ 12.1245354290 │ 14.3640523220 │ 13.0140825330 │ 13.6504071830 │ 0.4996041272 │ -0.0255325670 │ -0.8898205390 │ -0.6795143620 │ -0.5960067550 │ -0.9540908810 │ -0.4787146080 │ -3.1260369190 │ -1.8829258040 │ -2.8390737410 │ 0.3302467960 │ 0.6893793033 │ 0.5818057368 │ 0.7225216004 │ 0.6651089872 │ 0.8500082399 │ 0.2698209607 │ 0.4365973350 │ -0.0087577940 │ 0.0878970199 │ -6.3678356560 │ -5.1660893470 │ -5.6469380330 │ -4.5845715830 │ -3.8092605630 │ -4.3367767340 │ -2.2630145090 │ -1.1875447510 │ -0.1313669170 │ -2.5402238740 │ -6.0375888600 │ -4.4767100440 │ -5.0651322970 │ -3.8620499830 │ -3.1441515760 │ -3.4867684940 │ -1.9931935490 │ -0.7509474160 │ -0.1401247110 │ -2.4523268540 │ │ 50 │ 3 │ 6 │ 1 │ 17 │ Alabama │ Chambers County │ 34215 │ 34154 │ 34105 │ 34016 │ 34088 │ 34125 │ 33964 │ 33991 │ 33742 │ 33716 │ 33570 │ 33244 │ 32865 │ -49 │ -89 │ 72 │ 37 │ -161 │ 27 │ -249 │ -26 │ -146 │ -326 │ -379 │ 81 │ 400 │ 392 │ 407 │ 425 │ 422 │ 387 │ 380 │ 344 │ 362 │ 334 │ 80 │ 442 │ 476 │ 454 │ 455 │ 445 │ 444 │ 485 │ 415 │ 449 │ 519 │ 1 │ -42 │ -84 │ -47 │ -30 │ -23 │ -57 │ -105 │ -71 │ -87 │ -185 │ 6 │ 28 │ 34 │ 29 │ 32 │ 21 │ 18 │ 18 │ 19 │ 16 │ 13 │ -54 │ -74 │ 122 │ 57 │ -158 │ 31 │ -209 │ 65 │ -93 │ -255 │ -208 │ -48 │ -46 │ 156 │ 86 │ -126 │ 52 │ -191 │ 83 │ -74 │ -239 │ -195 │ -2 │ -1 │ 0 │ -2 │ -5 │ -2 │ -1 │ -4 │ -1 │ 0 │ 1 │ 458 │ 458 │ 458 │ 458 │ 458 │ 458 │ 458 │ 458 │ 458 │ 458 │ 458 │ 458 │ 11.7438088110 │ 11.5118054740 │ 11.9332092120 │ 12.4836610910 │ 12.4199838130 │ 11.4272215910 │ 11.2662693820 │ 10.2250096600 │ 10.8360523240 │ 10.1045243460 │ 12.9769087360 │ 13.9786209330 │ 13.3112456570 │ 13.3648606970 │ 13.0969023620 │ 13.1103007400 │ 14.3793175010 │ 12.3354040960 │ 13.4402969440 │ 15.7013417240 │ -1.2330999250 │ -2.4668154590 │ -1.3780364450 │ -0.8811996060 │ -0.6769185490 │ -1.6830791490 │ -3.1130481190 │ -2.1103944360 │ -2.6042446190 │ -5.5968173770 │ 0.8220666168 │ 0.9984729238 │ 0.8502778063 │ 0.9399462468 │ 0.6180560665 │ 0.5314986786 │ 0.5336653918 │ 0.5647534405 │ 0.4789415392 │ 0.3932898698 │ -2.1726046300 │ 3.5827557853 │ 1.6712356882 │ -4.6409845940 │ 0.9123684791 │ -6.1712902130 │ 1.9271250259 │ -2.7643194720 │ -7.6331307810 │ -6.2926379160 │ -1.3505380130 │ 4.5812287090 │ 2.5215134945 │ -3.7010383470 │ 1.5304245457 │ -5.6397915340 │ 2.4607904177 │ -2.1995660320 │ -7.1541892420 │ -5.8993480460 │ │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ … │ └────────┴────────┴──────────┴────────┴────────┴─────────┴─────────────────┴───────────────┴───────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴──────────────┴──────────────┴──────────────┴──────────────┴──────────────┴──────────────┴──────────────┴──────────────┴──────────────┴──────────────┴──────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────────┴────────────────┴────────────────┴────────────────┴────────────────┴────────────────┴────────────────┴────────────────┴────────────────┴────────────────┴────────────────┴──────────────────────┴──────────────────────┴──────────────────────┴──────────────────────┴──────────────────────┴──────────────────────┴──────────────────────┴──────────────────────┴──────────────────────┴──────────────────────┴──────────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴──────────────┴──────────────┴──────────────┴──────────────┴──────────────┴──────────────┴──────────────┴──────────────┴──────────────┴──────────────┴──────────────┴─────────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴───────────────────────┴───────────────────────┴───────────────────────┴───────────────────────┴───────────────────────┴───────────────────────┴───────────────────────┴───────────────────────┴───────────────────────┴───────────────────────┴──────────────────┴──────────────────┴──────────────────┴──────────────────┴──────────────────┴──────────────────┴──────────────────┴──────────────────┴──────────────────┴──────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┘
Let’s look at how many rows this table has
us_counties_pop.count()3194
and the number of columns
len(us_counties_pop.columns)180
That’s a lot of columns and we don’t need most of them. For our purposes, we won’t include most of them and we also need to create new columns. We’ll be using ibis to create more usable data sets from this raw data.
The raw data has the FIPS codes without leading zeros. We need them to have leading zeros because we’ll see later on, the geo json data that we need to merge with, has the FIPS codes with leading zeros. I could be wrong, but ibis doesn’t have a built-in way to add leading zeros like pandas does with its zfill() method. But, it is relatively easy to implement this once I discovered what ibis’ literal() does and that I can leverage the length() function also. I may submit a feature request to the ibis Github repo.
The transformations that are needed:
Based on the requirements above and leveraging ibis’ literal(), length(), mutate(), select(), and relabel() functions, I was able to satisfy those requirements
Ibis API allows you to “chain” your transformations, which is really nice for readability. You can also comment out one or more lines at a time to iteratively see those changes.
npopchg_by_county_2010_2020 = (
us_counties_pop
.mutate(state_fips=ibis.literal("0") * (2 - us_counties_pop.state.length()) + us_counties_pop.state)
.mutate(county_fips=ibis.literal("0") * (3 - us_counties_pop.county.length()) + us_counties_pop.county)
.mutate(id=_.state_fips + _.county_fips)
.mutate(npopchg_2010_2020=_.popestimate2020-_.popestimate2010)
.mutate(npopchg_2010_2020_perc_diff=(_.npopchg_2010_2020 / _.popestimate2010) * 100)
.select(_.id, _.state_fips, _.county_fips, _.stname, _.ctyname, _.popestimate2010, _.popestimate2020, _.npopchg_2010_2020, _.npopchg_2010_2020_perc_diff)
.relabel(
{
'stname': 'state_name',
'ctyname': 'county_name'
}
)
)npopchg_by_county_2010_2020┏━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ id ┃ state_fips ┃ county_fips ┃ state_name ┃ county_name ┃ popestimate2010 ┃ popestimate2020 ┃ npopchg_2010_2020 ┃ npopchg_2010_2020_perc_diff ┃ ┡━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ string │ string │ string │ string │ string │ int32 │ int32 │ int64 │ float64 │ ├────────┼────────────┼─────────────┼────────────┼─────────────────┼─────────────────┼─────────────────┼───────────────────┼─────────────────────────────┤ │ 01000 │ 01 │ 000 │ Alabama │ Alabama │ 4785514 │ 4921532 │ 136018 │ 2.842286 │ │ 01001 │ 01 │ 001 │ Alabama │ Autauga County │ 54761 │ 56145 │ 1384 │ 2.527346 │ │ 01003 │ 01 │ 003 │ Alabama │ Baldwin County │ 183121 │ 229287 │ 46166 │ 25.210653 │ │ 01005 │ 01 │ 005 │ Alabama │ Barbour County │ 27325 │ 24589 │ -2736 │ -10.012809 │ │ 01007 │ 01 │ 007 │ Alabama │ Bibb County │ 22858 │ 22136 │ -722 │ -3.158632 │ │ 01009 │ 01 │ 009 │ Alabama │ Blount County │ 57372 │ 57879 │ 507 │ 0.883706 │ │ 01011 │ 01 │ 011 │ Alabama │ Bullock County │ 10876 │ 9976 │ -900 │ -8.275101 │ │ 01013 │ 01 │ 013 │ Alabama │ Butler County │ 20933 │ 19504 │ -1429 │ -6.826542 │ │ 01015 │ 01 │ 015 │ Alabama │ Calhoun County │ 118420 │ 113469 │ -4951 │ -4.180882 │ │ 01017 │ 01 │ 017 │ Alabama │ Chambers County │ 34105 │ 32865 │ -1240 │ -3.635831 │ │ … │ … │ … │ … │ … │ … │ … │ … │ … │ └────────┴────────────┴─────────────┴────────────┴─────────────────┴─────────────────┴─────────────────┴───────────────────┴─────────────────────────────┘
npopchg_by_county_2010_2020.count()3194
con.create_table(name='npopchg_by_county_2010_2020', obj=npopchg_by_county_2010_2020, database='analysis', overwrite=True)┏━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ id ┃ state_fips ┃ county_fips ┃ state_name ┃ county_name ┃ popestimate2010 ┃ popestimate2020 ┃ npopchg_2010_2020 ┃ npopchg_2010_2020_perc_diff ┃ ┡━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ string │ string │ string │ string │ string │ int32 │ int32 │ int64 │ float64 │ ├────────┼────────────┼─────────────┼────────────┼─────────────────┼─────────────────┼─────────────────┼───────────────────┼─────────────────────────────┤ │ 01000 │ 01 │ 000 │ Alabama │ Alabama │ 4785514 │ 4921532 │ 136018 │ 2.842286 │ │ 01001 │ 01 │ 001 │ Alabama │ Autauga County │ 54761 │ 56145 │ 1384 │ 2.527346 │ │ 01003 │ 01 │ 003 │ Alabama │ Baldwin County │ 183121 │ 229287 │ 46166 │ 25.210653 │ │ 01005 │ 01 │ 005 │ Alabama │ Barbour County │ 27325 │ 24589 │ -2736 │ -10.012809 │ │ 01007 │ 01 │ 007 │ Alabama │ Bibb County │ 22858 │ 22136 │ -722 │ -3.158632 │ │ 01009 │ 01 │ 009 │ Alabama │ Blount County │ 57372 │ 57879 │ 507 │ 0.883706 │ │ 01011 │ 01 │ 011 │ Alabama │ Bullock County │ 10876 │ 9976 │ -900 │ -8.275101 │ │ 01013 │ 01 │ 013 │ Alabama │ Butler County │ 20933 │ 19504 │ -1429 │ -6.826542 │ │ 01015 │ 01 │ 015 │ Alabama │ Calhoun County │ 118420 │ 113469 │ -4951 │ -4.180882 │ │ 01017 │ 01 │ 017 │ Alabama │ Chambers County │ 34105 │ 32865 │ -1240 │ -3.635831 │ │ … │ … │ … │ … │ … │ … │ … │ … │ … │ └────────┴────────────┴─────────────┴────────────┴─────────────────┴─────────────────┴─────────────────┴───────────────────┴─────────────────────────────┘
Let’s recall what our npopchg_by_county_2010_2020 data looks like that we created earlier:
npopchg_by_county_2010_2020┏━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ id ┃ state_fips ┃ county_fips ┃ state_name ┃ county_name ┃ popestimate2010 ┃ popestimate2020 ┃ npopchg_2010_2020 ┃ npopchg_2010_2020_perc_diff ┃ ┡━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ string │ string │ string │ string │ string │ int32 │ int32 │ int64 │ float64 │ ├────────┼────────────┼─────────────┼────────────┼─────────────────┼─────────────────┼─────────────────┼───────────────────┼─────────────────────────────┤ │ 01000 │ 01 │ 000 │ Alabama │ Alabama │ 4785514 │ 4921532 │ 136018 │ 2.842286 │ │ 01001 │ 01 │ 001 │ Alabama │ Autauga County │ 54761 │ 56145 │ 1384 │ 2.527346 │ │ 01003 │ 01 │ 003 │ Alabama │ Baldwin County │ 183121 │ 229287 │ 46166 │ 25.210653 │ │ 01005 │ 01 │ 005 │ Alabama │ Barbour County │ 27325 │ 24589 │ -2736 │ -10.012809 │ │ 01007 │ 01 │ 007 │ Alabama │ Bibb County │ 22858 │ 22136 │ -722 │ -3.158632 │ │ 01009 │ 01 │ 009 │ Alabama │ Blount County │ 57372 │ 57879 │ 507 │ 0.883706 │ │ 01011 │ 01 │ 011 │ Alabama │ Bullock County │ 10876 │ 9976 │ -900 │ -8.275101 │ │ 01013 │ 01 │ 013 │ Alabama │ Butler County │ 20933 │ 19504 │ -1429 │ -6.826542 │ │ 01015 │ 01 │ 015 │ Alabama │ Calhoun County │ 118420 │ 113469 │ -4951 │ -4.180882 │ │ 01017 │ 01 │ 017 │ Alabama │ Chambers County │ 34105 │ 32865 │ -1240 │ -3.635831 │ │ … │ … │ … │ … │ … │ … │ … │ … │ … │ └────────┴────────────┴─────────────┴────────────┴─────────────────┴─────────────────┴─────────────────┴───────────────────┴─────────────────────────────┘
The data above has data broken up at the state and county level (“too granular”), but what we need instead, is to “roll the data up” or combine the population totals at the state level. To do this requires what is known as aggregating the data. What we need to accomplish this is to tell ibis to calculate the sum of the 2010 population totals for each state (the sums are aggregated or grouped by state) and do the same for the 2020 population totals.
Now, let’s make 2 data sets from this data set: one which has aggregate sum for year 2010 and the other has aggregate sum for year 2020. Then we will merge them together.
npopchg_2010 = npopchg_by_county_2010_2020.group_by(npopchg_by_county_2010_2020.state_name).aggregate(sum=npopchg_by_county_2010_2020.popestimate2010.sum()).relabel({"sum": "popestimate2010_sum"})
npopchg_2020 = npopchg_by_county_2010_2020.group_by(npopchg_by_county_2010_2020.state_name).aggregate(sum=npopchg_by_county_2010_2020.popestimate2020.sum()).relabel({"sum": "popestimate2020_sum"})Here’s what our 2010 data looks like:
npopchg_2010.head()┏━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓ ┃ state_name ┃ popestimate2010_sum ┃ ┡━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩ │ string │ int64 │ ├────────────────┼─────────────────────┤ │ Oklahoma │ 7520028 │ │ North Carolina │ 19149172 │ │ Colorado │ 10095078 │ │ Mississippi │ 5941230 │ │ Florida │ 37692286 │ └────────────────┴─────────────────────┘
Here’s what our 2020 data looks like:
npopchg_2020.head()┏━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓ ┃ state_name ┃ popestimate2020_sum ┃ ┡━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩ │ string │ int64 │ ├────────────────┼─────────────────────┤ │ Oklahoma │ 7961566 │ │ North Carolina │ 21201646 │ │ Colorado │ 11615438 │ │ Mississippi │ 5933572 │ │ Florida │ 43466624 │ └────────────────┴─────────────────────┘
inner_join() method and create additional columns using its mutate() methodnpopchg_by_state_2010_2020 = (
npopchg_2010
.inner_join(npopchg_2020, npopchg_2010.state_name == npopchg_2020.state_name)
.mutate(popestimate_diff=_.popestimate2020_sum - _.popestimate2010_sum)
.mutate(popestimate_perc_diff=(_.popestimate_diff / _.popestimate2010_sum) * 100)
.order_by(_.state_name)
)npopchg_by_state_2010_2020┏━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ state_name ┃ popestimate2010_sum ┃ popestimate2020_sum ┃ popestimate_diff ┃ popestimate_perc_diff ┃ ┡━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━┩ │ string │ int64 │ int64 │ int64 │ float64 │ ├──────────────────────┼─────────────────────┼─────────────────────┼──────────────────┼───────────────────────┤ │ Alabama │ 9571028 │ 9843064 │ 272036 │ 2.842286 │ │ Alaska │ 1427964 │ 1462316 │ 34352 │ 2.405663 │ │ Arizona │ 12814684 │ 14842802 │ 2028118 │ 15.826516 │ │ Arkansas │ 5843996 │ 6061044 │ 217048 │ 3.714034 │ │ California │ 74639100 │ 78736156 │ 4097056 │ 5.489155 │ │ Colorado │ 10095078 │ 11615438 │ 1520360 │ 15.060409 │ │ Connecticut │ 7158346 │ 7114012 │ -44334 │ -0.619333 │ │ Delaware │ 1799294 │ 1973618 │ 174324 │ 9.688467 │ │ District of Columbia │ 1210564 │ 1425632 │ 215068 │ 17.765934 │ │ Florida │ 37692286 │ 43466624 │ 5774338 │ 15.319681 │ │ … │ … │ … │ … │ … │ └──────────────────────┴─────────────────────┴─────────────────────┴──────────────────┴───────────────────────┘
As can be seen from above, we’ve added 2 new columns: popestimate_diff contains the population gain or loss from 2010 to 2020 and another column representing this as a percentage (popestimate_perc_diff).
Let’s see how many rows we have
npopchg_by_state_2010_2020.count()51
If you’re wondering why we have 51 states and not 50 states, it is because “District of Columbia” was also included as a state.
con.create_table(name='npopchg_by_state_2010_2020', obj=npopchg_by_state_2010_2020, database='analysis', overwrite=True)┏━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ state_name ┃ popestimate2010_sum ┃ popestimate2020_sum ┃ popestimate_diff ┃ popestimate_perc_diff ┃ ┡━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━┩ │ string │ int64 │ int64 │ int64 │ float64 │ ├──────────────────────┼─────────────────────┼─────────────────────┼──────────────────┼───────────────────────┤ │ Alabama │ 9571028 │ 9843064 │ 272036 │ 2.842286 │ │ Alaska │ 1427964 │ 1462316 │ 34352 │ 2.405663 │ │ Arizona │ 12814684 │ 14842802 │ 2028118 │ 15.826516 │ │ Arkansas │ 5843996 │ 6061044 │ 217048 │ 3.714034 │ │ California │ 74639100 │ 78736156 │ 4097056 │ 5.489155 │ │ Colorado │ 10095078 │ 11615438 │ 1520360 │ 15.060409 │ │ Connecticut │ 7158346 │ 7114012 │ -44334 │ -0.619333 │ │ Delaware │ 1799294 │ 1973618 │ 174324 │ 9.688467 │ │ District of Columbia │ 1210564 │ 1425632 │ 215068 │ 17.765934 │ │ Florida │ 37692286 │ 43466624 │ 5774338 │ 15.319681 │ │ … │ … │ … │ … │ … │ └──────────────────────┴─────────────────────┴─────────────────────┴──────────────────┴───────────────────────┘
When using Plotly and to plot at the state level, we need to obtain 2-character state codes. Our table we just created doesn’t have it, but luckily we have a table that maps state name to its corresponding 2-character state code in our Postgres database.
us_states = con.table('us_states')us_states┏━━━━━━━━━━━━━┳━━━━━━━━━━━━┓ ┃ state_name ┃ state_code ┃ ┡━━━━━━━━━━━━━╇━━━━━━━━━━━━┩ │ string │ string │ ├─────────────┼────────────┤ │ Alabama │ AL │ │ Alaska │ AK │ │ Arizona │ AZ │ │ Arkansas │ AR │ │ California │ CA │ │ Colorado │ CO │ │ Connecticut │ CT │ │ Delaware │ DE │ │ Florida │ FL │ │ Georgia │ GA │ │ … │ … │ └─────────────┴────────────┘
us_states.count()51
Let’s confirm it has District of Columbia and its corresponding state code
us_states.filter(us_states.state_name.contains("District"))┏━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓ ┃ state_name ┃ state_code ┃ ┡━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩ │ string │ string │ ├──────────────────────┼────────────┤ │ District of Columbia │ DC │ └──────────────────────┴────────────┘
Now, we’ll merge our table we created earlier to this state name to state code table so that our data will have the 2-character state code included
npopchg_by_state_2010_2020 = npopchg_by_state_2010_2020.inner_join(us_states, npopchg_by_state_2010_2020.state_name == us_states.state_name)npopchg_by_state_2010_2020┏━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓ ┃ state_name ┃ popestimate2010_sum ┃ popestimate2020_sum ┃ popestimate_diff ┃ popestimate_perc_diff ┃ state_code ┃ ┡━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩ │ string │ int64 │ int64 │ int64 │ float64 │ string │ ├──────────────────────┼─────────────────────┼─────────────────────┼──────────────────┼───────────────────────┼────────────┤ │ Alabama │ 9571028 │ 9843064 │ 272036 │ 2.842286 │ AL │ │ Alaska │ 1427964 │ 1462316 │ 34352 │ 2.405663 │ AK │ │ Arizona │ 12814684 │ 14842802 │ 2028118 │ 15.826516 │ AZ │ │ Arkansas │ 5843996 │ 6061044 │ 217048 │ 3.714034 │ AR │ │ California │ 74639100 │ 78736156 │ 4097056 │ 5.489155 │ CA │ │ Colorado │ 10095078 │ 11615438 │ 1520360 │ 15.060409 │ CO │ │ Connecticut │ 7158346 │ 7114012 │ -44334 │ -0.619333 │ CT │ │ Delaware │ 1799294 │ 1973618 │ 174324 │ 9.688467 │ DE │ │ District of Columbia │ 1210564 │ 1425632 │ 215068 │ 17.765934 │ DC │ │ Florida │ 37692286 │ 43466624 │ 5774338 │ 15.319681 │ FL │ │ … │ … │ … │ … │ … │ … │ └──────────────────────┴─────────────────────┴─────────────────────┴──────────────────┴───────────────────────┴────────────┘
Using Plotly with ibis table expressions isn’t supported, but we can easily convert our ibis table expression to a pandas dataframe using to_pandas() method
df_npopchg_by_state_2010_2020 = npopchg_by_state_2010_2020.to_pandas()type(df_npopchg_by_state_2010_2020)pandas.core.frame.DataFrame
Let’s create a Plotly choropleth map of the population difference from 2010 to 2020
import plotly.express as px
fig = px.choropleth(
df_npopchg_by_state_2010_2020,
locations='state_code',
locationmode="USA-states",
scope="usa",
color='popestimate_diff',
color_continuous_scale="YlGnBu",
title='2010 to 2020 Population Change',
labels={'popestimate_diff': 'Population Diff.'},
width=1200,
height=600,
)
fig.show()import plotly.express as px
fig = px.choropleth(
df_npopchg_by_state_2010_2020,
locations='state_code',
locationmode="USA-states",
scope="usa",
color='popestimate_perc_diff',
color_continuous_scale="YlGnBu",
title='2010 to 2020 % Population Change',
labels={'state_name': 'State Name', 'popestimate_perc_diff': '2010 to 2020 % Diff'},
width=1200,
height=600,
)
fig.show()Per Plotly’s documenation, we need to obtain geo json data
from urllib.request import urlopen
import json
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
counties = json.load(response)npopchg_by_county_2010_2020┏━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ id ┃ state_fips ┃ county_fips ┃ state_name ┃ county_name ┃ popestimate2010 ┃ popestimate2020 ┃ npopchg_2010_2020 ┃ npopchg_2010_2020_perc_diff ┃ ┡━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ string │ string │ string │ string │ string │ int32 │ int32 │ int64 │ float64 │ ├────────┼────────────┼─────────────┼────────────┼─────────────────┼─────────────────┼─────────────────┼───────────────────┼─────────────────────────────┤ │ 01000 │ 01 │ 000 │ Alabama │ Alabama │ 4785514 │ 4921532 │ 136018 │ 2.842286 │ │ 01001 │ 01 │ 001 │ Alabama │ Autauga County │ 54761 │ 56145 │ 1384 │ 2.527346 │ │ 01003 │ 01 │ 003 │ Alabama │ Baldwin County │ 183121 │ 229287 │ 46166 │ 25.210653 │ │ 01005 │ 01 │ 005 │ Alabama │ Barbour County │ 27325 │ 24589 │ -2736 │ -10.012809 │ │ 01007 │ 01 │ 007 │ Alabama │ Bibb County │ 22858 │ 22136 │ -722 │ -3.158632 │ │ 01009 │ 01 │ 009 │ Alabama │ Blount County │ 57372 │ 57879 │ 507 │ 0.883706 │ │ 01011 │ 01 │ 011 │ Alabama │ Bullock County │ 10876 │ 9976 │ -900 │ -8.275101 │ │ 01013 │ 01 │ 013 │ Alabama │ Butler County │ 20933 │ 19504 │ -1429 │ -6.826542 │ │ 01015 │ 01 │ 015 │ Alabama │ Calhoun County │ 118420 │ 113469 │ -4951 │ -4.180882 │ │ 01017 │ 01 │ 017 │ Alabama │ Chambers County │ 34105 │ 32865 │ -1240 │ -3.635831 │ │ … │ … │ … │ … │ … │ … │ … │ … │ … │ └────────┴────────────┴─────────────┴────────────┴─────────────────┴─────────────────┴─────────────────┴───────────────────┴─────────────────────────────┘
Looks good, so now convert this ibis table expresssion to pandas dataframe:
df_npopchg_by_county_2010_2020 = npopchg_by_county_2010_2020.to_pandas()import plotly.express as px
fig = px.choropleth(
df_npopchg_by_county_2010_2020,
geojson=counties,
locations='id',
color='npopchg_2010_2020',
color_continuous_scale="YlGnBu",
range_color=(500, 100000),
scope="usa",
hover_data=['state_name','county_name'],
labels={'state_name': 'State Name', 'county_name': 'County Name', 'npopchg_2010_2020': '2010 to 2020 diff'},
width=1200,
height=600,
title='2010 to 2020 Population Change',
)
fig.show()import plotly.express as px
fig = px.choropleth(
df_npopchg_by_county_2010_2020,
geojson=counties,
locations='id',
color='npopchg_2010_2020_perc_diff',
color_continuous_scale="YlGnBu",
range_color=(-20, 80),
scope="usa",
hover_data=['state_name','county_name'],
labels={'state_name': 'State Name', 'county_name': 'County Name', 'npopchg_2010_2020_perc_diff': '2010 to 2020 % diff'},
width=1200,
height=600,
title='2010 to 2020 % Population Change',
)
fig.show()counties